<?php
require_once '../includes/funciones.php';

//include ("seguridad.php");

conexion(); //conexión a la base de datos
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title><?php titulopanel(); ?></title>
<link rel="STYLESHEET" type="text/css" href="estilo.css">
<script type="text/javascript" src="../plugins/jquery.js"></script>
<script type="text/javascript" src="../plugins/jquery_validate/jquery.validate.js"></script>
<script type="text/javascript" src="../plugins/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
    mode : 'exact',
    theme : 'advanced',
	elements: 'summary, conten',
    theme_advanced_buttons1 : 'bold,italic,underline,undo,redo',
    theme_advanced_buttons2 : '',
    theme_advanced_buttons3 : '',
    theme_advanced_toolbar_location : 'top',
    theme_advanced_toolbar_align : 'left',    
    init_instance_callback : "initialiseInstance"
});


$(document).ready(function() {
$("input[type='submit']").click(function() {
tinyMCE.triggerSave();
})
})
	
</script>
<script>
  $(document).ready(function(){
		
	$("#newsForm").validate({
		rules: {			
			categorie: {
				required: true
				},
			title: {
				required: true
					},
			summary: {
				required: true
				},
			conten: {
					required: true
					}	
		},				
					
                
		messages: {
			categorie: {
				required: "Seleccione una categoria"
				
						},

            title:{
                required: "Coloque un t�tulo"
                    },
                    
            summary:{
                required:"Coloque un copete"        
                     },        
            conten: "Coloque un cuerpo"		
                    
			}
	});
	
  });
 
</script>

<!-- /ERRORES -->

</head>

<body>
<div id="contenedor">

		<div id="encabezado"><?php include('header.php') ?></div><!--fin de encabezado-->



	<div id="menuizquierda"><?php include('menu.php') ?></div>	<!--fin de menuizquierda-->

	<div id="content">


	<div id="formulario">

	<?php			

        if(isset($_GET['var']))
        {
            $var=sqlint($_GET['var']);
            $result=mysql_query("select * from news where id=$var");

            if(mysql_num_rows($result) !=0)
            {
                while($row=mysql_fetch_array($result))
		{
                    $impresos++; //me va aumentando por cada uno asi despues puedo usar para la PAGINACION

                    $id_news=$row['id'];
                    $title=$row['title'];
                    $body=$row['body'];
                    $fecha=cambiarFechaMostrar($row['date']);
                    $publishedbd=$row['is_published'];
		}

		mysql_free_result($result);
}
else{ 
	$_SESSION["errorborrarnoticia"]="noexiste"; #uso la misma session de borrar noticia
	header	("location: noticias.php");
}

?>
		

	<br/>
<span class="title">Modificar Noticia</span>	
	
			
			<br>
			<form class="admin" id="newsForm" name="newsForm" action="control_noticias.php" method="post"  enctype="multipart/form-data">
			<br>
			<fieldset class="admin">
			<legend>Noticia</legend>
			<p><span>Publicar:</span>
			
			<?php 
			if($publishedbd==1){
				echo '<input type="checkbox" name="published" value="1" checked />';
				 
				}else{
					
				echo '<input type="checkbox" name="published" value="1" />';		
				}
			
			
			?>
			<!--</p>
			<br>
			<p><span>Categoria:</span>
			<select name="categorie" id="categorie" class="required">
			<option value ='<?php echo $categorie?>'><?php echo $rowcategorie['description']?></option>
			
			<?php
			$concla= mysql_query("SELECT * FROM categories where id_grupos = 1 and id !=5 and id!= $categorie");  
			while($rowconcla=mysql_fetch_array($concla))
				{
				echo '<option value="'.$rowconcla['id'].'">'.$rowconcla['description'].' </option>';
				}
			?>
			</select>
			</p>
			<br>  -->
			<br>
			<p><span>Fecha:</span>
			<input type="text" name="date" value="<?php echo $fecha?>">
			</p>
			<br>
			<br>
			
			<p><span>T&iacute;tulo:</span>
			<input type="text" name="title" id="title" onkeyup="if (this.value.length == 139) this.disabled = true;" size="70px" value="<?php echo $title?>">
			</p>
			<br>  <br><br><br>
			
			<p><span>
				Cuerpo:
				</span>				
				<textarea name="body" id="body" cols="60" rows="10"><?php echo limpiar_parr($body)?></textarea>
			</p>
			<br>
			</fieldset>


<br/>
<fieldset class="admin">
<?php 
$respfoto=mysql_query("select * from images where new_id='$id_news'");
		
if(mysql_num_rows($respfoto)!=0){					
	while($rows = mysql_fetch_array($respfoto)) {
		$url=$rows['url'];
		$folder=$rows['folder'];				
		echo '<br><img width="300px" src=../'.$folder.$url.'>';
		$comment=$rows['comment'];
		echo'<br><br>Borrar Foto<br>';
		echo '<input type="checkbox" name="delpicture" value="1"/>';
		echo '<br><br>';
		
	}
}
?>

			<legend >Imagen</legend>
				<p><span>Cargar una Imagen:</span>
				</p>
				
				<input type="file" name="imagen"><br>
				<input type="hidden" name="MAX_FILE_SIZE" value="100000">
				
				<p><span>Comentario:</span>
				
				<input type="text" name="comment" size="60" value="<?php echo $comment?>">
				</p>
				
				<br>
</fieldset>

			<input name="boton" type="hidden" id="boton" value="2"></input>
			<input name="id_news" type="hidden" id="boton" value="<?php echo $id_news?>"></input>
			<input name="publishedbd" type="hidden" id="boton" value="<?php echo $publishedbd?>"></input>
			<input name="createdbd" type="hidden" id="boton" value="<?php echo $createdbd?>"></input>
			
			
			
			<br>
			<input type="submit" class="buttonadmin" value="Modificar" style="width:75px">
			<a class="enlacecancelar" href="noticias.php"><input type="button" class="buttoncancelar" value="Cancelar"></a>
			<br>
</form>

<br>
<?php }#Cierra el IF del isset($_GET['var'])?> 
	
		</div><!-- formulario -->

	</div><!--content-->


<div id="piepagina">

</div>
<!--fin de piepagina-->

</div><!-- contenedor -->

</body>

</html>